package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FirstServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// Handle HTTP GET request
		resp.setCharacterEncoding("UTF-8");
		PrintWriter out = resp.getWriter();
		out.print("<html>");
		out.print("<head>");
		out.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
		out.print("<title>Insert title here</title>");
		out.print("</head>");
		out.print("<body>");
		out.print("<p>This HTML is generated by FirstServlet, " +
				"and its content is the same as page2.jsp except this paragraph.</p>");
		for (int i = 0; i < 5; i++) {
			out.print("<p>");
			out.print(i);
			out.print("</p>");
		}
		out.print("</body>");
		out.print("</html>");
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// Handle HTTP POST request
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String name=req.getParameter("name");
		String age=req.getParameter("age");
		PrintWriter out = resp.getWriter();
		out.print("<html>");
		out.print("<head>");
		out.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
		out.print("<title>Test for post</title>");
		out.print("</head>");
		out.print("<body>");
		out.print("<p>"+name+"'s age is "+age+"</p>");
		out.print("</body>");
		out.print("</html>");
	}

}
